package autotest;

import org.junit.Assert;
import org.junit.Test;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class ToSpringEl{

	@Test  
	public void testVariableExpression() {  
	    ExpressionParser parser = new SpelExpressionParser();  
	    EvaluationContext context = new StandardEvaluationContext();  
	    context.setVariable("variable", "haha");  
	    context.setVariable("variable", "haha");  
	    String result1 = parser.parseExpression("#variable").getValue(context, String.class);  
	    Assert.assertEquals("haha", result1);  
	   
	    context = new StandardEvaluationContext("haha");  
	    String result2 = parser.parseExpression("#root").getValue(context, String.class);  
	    Assert.assertEquals("haha", result2);  
	    String result3 = parser.parseExpression("#this").getValue(context, String.class);  
	    Assert.assertEquals("haha", result3);  
	}  
}
